//格式化时间
function formateDate (date,type) {
    date === undefined ? date = new Date() : date = date ;
    const Date = new Date(date);
    let year = Date.getFullYear();
    let month = Date.getMonth() + 1;
}

//权限与路由关系
import Layout from '@/layout';
const permissionRoutes = [
    {
        id:"001",
        name:"内存条基表导入",
        router:{
            path: '/memory',
            component: Layout,
            redirect: '/memoryImport',
            children: [
              {
                path: '/memoryImport',
                name: 'memoryImport',
                component: () => import('@/views/memoryImport/index.vue'),
                meta: { title: '内存条基表导入', icon: 'el-icon-tickets', keepAlive:false }
              }
            ]
        },
    },
    {
        id:"002",
        name:"散件排产订单导入",
        router:{
            path:"/productOrder",
            component:Layout,
            redirect:"/productOrderImport",
            children:[
                {
                path:"/productOrderImport",
                name:"ProductOrderImport",
                component: () => import("@/views/productOrderImport/index.vue"),
                meta:{ title:"散件排产订单导入", icon:"el-icon-document" , keepAlive:false}
                }
            ]
        }
    },
    {
        id:"003",
        name:"散备件校验",
        router:{
            path:'/replacement',
            component: Layout,
            redirect: '/replacementVerify',
            children:[
              {
                path:"/replacementVerify",
                name:"replacementVerify",
                component: () => import ("@/views/replacementVerify/index.vue"),
                meta:{title:"散备件校验", icon:"el-icon-notebook-1", keepAlive:true}
              }
            ]
        }
    },
    {
        id:"004",
        name:"一致性校验",
        router:{
            path:'/consistency',
            component: Layout,
            redirect: '/consistencyVerify',
            children:[
              {
                path:"/consistencyVerify",
                name:"ConsistencyVerify",
                component: () => import ("@/views/consistencyVerify/index.vue"),
                meta:{title:"一致性校验", icon:"el-icon-notebook-2", keepAlive:true}
              }
            ]
        }
    },
    {
      id:"008",
      name:"包装校验",
      router:{
        path:"/packing",
        component:Layout,
        redirect:"/packingVerify",
        children:[
          {
            path:"/packingVerify",
            name:"packingVerify",
            component:()=>import("@/views/packingVerify/index.vue"),
            meta:{title:'包装校验',icon:'el-icon-suitcase',keepAlive:false}
          }
        ]
      }
    },
    {
        id:"005",
        name:"质检员设置",
        router:{
            path:'/setting',
            component: Layout,
            redirect: '/userSetting',
            children:[
              {
                path:"/userSetting",
                name:"UserSetting",
                component: () => import ("@/views/inspectorInfo/index.vue"),
                meta:{title:"质检员设置", icon:"el-icon-user", keepAlive:false}
              }
            ]
        }
    },
    {
        id:"006",
        name:"RPA查看IP",
        router:{
            path:'/rpa',
            component: Layout,
            redirect: '/rpaTable',
            children:[
              {
                path:"/rpatable",
                name:"Rpatable",
                component: () => import ("@/views/rpaTable/index.vue"),
                meta:{title:"RPA查看IP", icon:"el-icon-connection", keepAlive:false}
              }
            ]
        }
    },
    {
        id:"007",
        name:"用户管理",
        router:{
            path:"/user",
            component:Layout,
            redirect:"/userList",
            meta:{title:"用户管理", icon:"el-icon-s-grid"},
            children:[
              {
                path:"/userList",
                name:"userList",
                component: () => import("@/views/userList/index.vue"),
                meta:{ title:"用户信息", icon:"el-icon-user-solid" , keepAlive:false}
              },
              {
                path:"/rolePermission",
                name:"userPermission",
                component: () => import("@/views/userPermission/index.vue"),
                meta:{title:"角色权限",icon:"el-icon-s-operation",keepAlive:false}
              }
            ]
        }
    }
];

//封装获取当前时间的功能函数
function getNowTime () {
  let date = new Date();
  //年 getFullYear():四位数字返回年份
  let year = date.getFullYear();
  //月 getMonth():0-11
  let month = date.getMonth() + 1;
  //日 getDate():1-31
  let day = date.getDate();
  //时 getHours():0-23
  let hour = date.getHours();
  //分 getMinutes():0-59
  let minute = date.getMinutes();
  //秒 getSeconds():0-59
  let second = date.getSeconds();
  //返回时间
  let time = year + '年' + addZero(month) + '月' + addZero(day) + '日 ' + addZero(hour) + ':' + addZero(minute) + ':' + addZero(second);
  return time;
}
//补零函数
function addZero(value){
  return value < 10 ? ('0' + value) : value;
}

//节流函数
function thorttle (fun, interval) {
  let last = 0;
  let timer = null;
  return function () {
      const _this = this;
      const _args = arguments;
      let now = new Date().getTime();
      if(now - last > interval){
          if(timer){
              clearTimeout(timer);
              timer = null;
          }

          fun.apply(_this, _args);
          last = now;
      } else if (timer == null) {
          //只是最后一次开启
          timer = setTimeout(()=>{
              timer = null;
              fun.apply(_this, _args);
          },interval)
      }
  }
}

//防抖函数
function debounce (fun, delay) {
  let timer = null;

  return function () {
      const _this = this;
      const _args = arguments;
      if(timer != null){
          //未执行完成，又再次触发,清除定时器
          clearTimeout(timer);
      }

      timer = setTimeout(() => {
          //执行对应的功能函数
          fun.call(_this,_args);
      }, delay)
  }
}

export { permissionRoutes, getNowTime, thorttle, debounce };